import { showNotice } from '@/utils/toolclass'
import { logPhoneCode } from '@/api/user'

const sendCode = {
  send(phone, count, sendMsg, disabled) {
    count++
    if (count <= 10) {
      if (phone !== undefined && (/^1[3456789]\d{9}$/.test(phone))) {
        let time = 60
        const timer = setInterval(() => {
          time--
          if (time === 0) {
            clearInterval(timer)
            sendMsg = '获取验证码'
            disabled = false
            return
          }
          sendMsg = time + 's后重新发送'
        }, 1000)
        disabled = true
        // this.getCode(phone)
        showNotice('success', '提示', '验证码发送成功')
      }
    } else {
      showNotice('error', '提示', '一天只能发送10次验证码')
    }
  }
  // getCode(phone) {
  //   if (phone !== undefined && !(/^1[3456789]\d{9}$/.test(phone))) {
  //     showNotice('error', '提示', '输入的手机号码有误,请重新输入')
  //   } else {
  //     logPhoneCode(phone).then(res => {
  //       console.log(res)
  //       return res
  //     })
  //   }
  // }
}

export default sendCode
